﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;

namespace Ramparts
{
    class LevelEditor : Scene
    {

        SpriteSheet iso_tiles;
        int showIndex;

        public LevelEditor(SceneManager sceneManager)
        {
            Texture2D isoTiles= sceneManager.rampart.Content.Load<Texture2D>("Content\\tetris_tiles_placed");
            iso_tiles = new SpriteSheet(isoTiles);
            iso_tiles.BatchAddSourceSprite(20, 20);
            this.sceneManager = sceneManager;
        }

        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
            processKeyboardEvents(gameTime);
            processMouseEvents(gameTime);
                       
        }

        protected override void processMouseEvents(GameTime gameTime)
        {
            base.processMouseEvents(gameTime);
          
        }

        protected override void processKeyboardEvents(GameTime gameTime)
        {
            base.processKeyboardEvents(gameTime);
            if (currentKeyboardState.IsKeyDown(Keys.Left) && previousKeyboardState.IsKeyUp(Keys.Left))
            {
                showIndex -= 1;
                if (showIndex < 0)
                    showIndex = 0;
                Console.WriteLine("Index: " + showIndex);
            }

            if (currentKeyboardState.IsKeyDown(Keys.Right) && previousKeyboardState.IsKeyUp(Keys.Right))
            {
                showIndex += 1;
                if (showIndex > 20)
                    showIndex = 20;
                Console.WriteLine("Index: " + showIndex);
            }
            previousKeyboardState = currentKeyboardState;              
            
        }

        public override void drawScene()
        {
            base.drawScene();
            iso_tiles.drawTextureByIndex(showIndex, 100, 100, sceneManager.rampart.spriteBatch);
            sceneManager.rampart.spriteBatch.End();

        }

    }
}
